// get 在req.query, post在req.body
module.exports = class DefaultDao extends require('../model/default_mod.js') {
  // 获取文章列表
  static async getAllArticleList(req, res) {
    const data = await this.getAllArticleListMod()
    res.json({
      data,
    })
  }

  // 根据文章Id获取文章信息
  static async getArticleById(req, res) {
    const data = await this.getArticleByIdMod(req.query.id)
    res.json({
      data,
    })
  }

  // 获取菜单标题名称和编号
  static async getTypeInfo(req, res) {
    const data = await this.getTypeInfoMod(req, res)
    res.json({
      data,
    })
  }

  // 增加网站访客数
  static async addTodayVisitor(req, res) {
    const data = await this.addTodayVisitorMod()
    res.json({
      status: 200,
      statusText: 'ok',
    })
  }

  // 增加文章发访问数
  static async addArticleVisitor(req, res) {
    const data = await this.addArticleVisitorMod(req.body.articleId)
    res.json({
      status: 200,
      statusText: 'ok',
    })
  }

  // 根据文章类型获取文章
  static async getArticleByTag(req, res) {
    console.log(req.query)
    const data = await this.getArticleByTagMod(req.query.tagId, req.query.pageNum, req.query.pageSize)
    res.json({
      status: 200,
      statusText: 'ok',
      data,
    })
  }

  // 获取推荐文章
  static async getRecommendArticle(req, res) {
    const data = await this.getRecommendArticleMod(req.query.keywords, req.query.num)
    res.json({
      status: 200,
      statusText: 'ok',
      data,
    })
  }

  // 获得文章类型及数量
  static async getArticleTypeAndAmount(req, res) {
    const data = await this.getArticleTypeAndAmountMod(req.query.tagId)
    res.json({
      status: 200,
      statusText: 'ok',
      data,
    })
  }

  // 添加评论
  static async addArticleComment(req, res) {
    const { articleId, author, content, avatar } = req.body
    const data = await this.addArticleCommentMod(articleId, author, content, avatar)
    res.json({
      status: 200,
      statusText: 'ok',
      data,
    })
  }

  // 根据文章Id获取文章评论
  static async getArticleCommentById(req, res) {
    const data = await this.getArticleCommentByIdMod(req.query.articleId)
    res.json({
      status: 200,
      statusText: 'ok',
      data,
    })
  }

  // 更新评论点赞数
  static async updateCommentPrefer(req, res) {
    const data = await this.updateCommentPreferMod(req.body.id, req.body.keywords)
    res.json({
      status: 200,
      statusText: 'ok',
      data,
    })
  }
}
